package com.springboot.springbootredis.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisCluster;

/**
 * @Author: TongRui乀
 * @Date: 2019/1/15 11:15
 * @description：
 */
@RestController
@RequestMapping("redis")
public class IndexController {

    @Autowired
    private JedisCluster jedisCluster;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("set/{key}/{value}")
    public String set(@PathVariable String key, @PathVariable String value){

        String set = this.jedisCluster.set(key, value);

        return set;
    }

    @GetMapping("get/{key}")
    public String get(@PathVariable String key){

        String s = this.jedisCluster.get(key);

        return s;
    }


    @GetMapping("single/{key}/{value}")
    public String setSingle(@PathVariable String key, @PathVariable String value){

        this.redisTemplate.opsForValue().set(key, value);

        return "success";
    }

}
